package com.hxc.common.utils;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.nio.charset.Charset;

public class MyByteSerialize extends JsonSerializer<byte[]> {

    @Override
    public void serialize(byte[] value, JsonGenerator gen, SerializerProvider serializers)
            throws IOException, JsonProcessingException {

        if (null == value || 0 == value.length) {
            gen.writeString("");
        }

        gen.writeString(new String(value, Charset.defaultCharset()));
    }

}
